package com.hngy.xpq.sjxuiautomator;

import android.util.Log;

import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.rule.ActivityTestRule;

import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.action.ViewActions.closeSoftKeyboard;
import static androidx.test.espresso.action.ViewActions.typeText;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withText;
import static org.junit.Assert.*;

/**
 * Instrumented test, which will execute on an Android device.
 *
 * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
 */
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {

    @Rule
    public ActivityTestRule activityTestRule = new ActivityTestRule(MainActivity.class);

    @Test
    public void useAppContext() throws InterruptedException {
        // Context of the app under test.
        String[][] test = arrayData.getArrayData();
        for (String[] a : test) {
            String t = "[" + a[0] + ", " + a[1] + ", " + a[2] + "]";
            onView(withId(R.id.test)).perform(typeText(t),closeSoftKeyboard());
            onView(withId(R.id.one)).perform(typeText(a[0]),closeSoftKeyboard());
            onView(withId(R.id.two)).perform(typeText(a[1]), closeSoftKeyboard());
            onView(withId(R.id.three)).perform(typeText(a[2]), closeSoftKeyboard());
            onView(withId(R.id.tj)).perform(click());
            // 通过文本内容操作控件
            onView(withText("清空")).perform(click());
        }
        activityTestRule.getActivity();
    }
}